﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KiDS_Bootstrap
{
	/// <summary>
	/// Klasa koja enkapsulira servent u sistemu
	/// </summary>
	public class Servent
	{
		private readonly short _port;
		private readonly string _address;
		private readonly string _location;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="address">Adresa na koju se zelimo konektovati, prosledjena u obliku broj.broj.broj.broj</param>
		/// <param name="port">Port preko koga treba izvrsiti komunikaciju</param>
		/// <param name="location">Reprezentacija serventa u obliku fizicke lokacije</param>
		public Servent(string address, short port, string location)
		{
			_port = port;
			if (address == "127.0.0.1" || address == "0.0.0.0")
				_address = Properties.Settings.Default.DefaultLokacija;
			else _address = address;
			_location = location;
		}

		public string Address
		{
			get
			{
				return _address;
			}
		}

		public short Port
		{
			get
			{
				return _port;
			}
		}

		public string Location
		{
			get
			{
				return _location;
			}
		}

		public override string ToString()
		{
			return Native.AddressToBytes(_address) + ":" + _port + ":" + _location;
		}

		public static bool operator ==(Servent s1, Servent s2){
			return s1._address == s2._address && s1._location == s2._location && s1._port == s2._port;
		}

		public static bool operator !=(Servent s1, Servent s2)
		{
			return s1._address != s2._address || s1._location != s2._location || s1._port != s2._port;
		}
	}
}
